/**
 * TMP001显示
 * */


var formList = {}; //门店数据
var cateList = []; //分类数据
var goodsList = []; //商品数据
var commentList = {
    data: [], //列表数据
    total: 0, //记录总数
    pages: {
        start: 0, //起始页0
        limit: 5, //每页记录数5
        moreFlag: 0 //更多标记：0继续，1没有了
    }
}; //评论数据
var followList = {
    data: [], //列表数据
    total: 0, //记录总数
    pages: {
        start: 0, //起始页0
        limit: 5, //每页记录数5
        moreFlag: 0 //更多标记：0继续，1没有了
    }
}; //关注数据
var cartList = []; //购物车列表
var orderList = {
    orderno: '',
    gnum: 0,
    totalPrice: 0,
    goodsList: [] //商品列表
}; //订单列表


/**
 * 获取门店
 * */
function getOne(){
    //if (token == '') {
    //    msgPop({msg: '没有登录'});
    //    setTimeout(function(){
    //        window.location.href = '/login.html?code=' + code;
    //    }, 1000);
    //    return
    //}
    if (code == '' || code == undefined) {
        msgPop({msg: '码值错误'});
        return
    }
    var formData = {
        token: token,
        code: code,
    };
    $.ajax({
        type: apis.shop1One.method,
        url: apis.shop1One.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            formList = res.data;
            var followBtn = '<span>关注0</span>';
            if (res.data.isfollow == 0) {
                followBtn = '<span class="click" onclick="setFollow();">未关注</span>';
            } else {
                followBtn = '<span onclick="setFollow();">已关注</span>';
            }
            $('#shopName').html(res.data.shop_name + followBtn);
            $('#laba').html('公告：' + res.data.describe);
            $('#headimg').html('<img src="' + res.data.headimg + '"/>');
            $('#shopimg').html('<img src="' + res.data.bgimg + '"/>');
            $('#advert').html('<div><img src="' + res.data.adimg + '"/></div>');
            getReduceHtml();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//优惠信息
function getReduceHtml(){
    var h = '', i, reduces = formList.reduceList;
    if (reduces.length == 0) { return }
    h += '<tr><td>';
    for (i = 0; i < reduces.length; i ++) {
        h += '<span>';
        h += reduces[i].full;
        h += '减';
        h += reduces[i].reduce;
        h += '</span>';
    }
    h += '<td><tr>';
    $('#youhui').html(h);
}


//切换菜单
function setMenu(v){
    $('.mli').removeClass('click');
    $('#mli-' + v).addClass('click');
    $('.body').hide();
    $('#body' + v).show();
    var cartPop = $('#cartPop');
    if (v == 1) {
        cartPop.show();
    } else {
        cartPop.hide();
    }
    if (v == 2) {
        getCommentList();
    }
    if (v == 3) {
        getFollowList();
    }
}


//拼接字符串
function getHtml(){
    var cw = document.documentElement.clientWidth;
    var ch = document.documentElement.clientHeight;
    var cates = [
        {id: 1, title: '卤味'},
        {id: 2, title: '新品小炒'},
        {id: 2, title: '新品小炒'},
        {id: 2, title: '新品小炒'},
        {id: 3, title: '农家小炒'},
        {id: 3, title: '农家小炒'},
        {id: 3, title: '农家小炒'}
    ];
    var foods = [
        {id: 1, title: '青椒肉丝', price: 10, monthSale: 0, likeNum: 0, cover: ''},
        {id: 2, title: '小炒肉', price: 10, monthSale: 0, likeNum: 0, cover: ''},
        {id: 3, title: '回锅肉', price: 10, monthSale: 0, likeNum: 0, cover: ''}
    ];
    var h = '', i;
    //菜单
    h += '<style type="text/css">td{vertical-align: top;} .liCate{padding: 8px 0; padding-right: 10px; width: 80px; text-align: center; color: #888; font-size: 12px;} .liClick{background: #eee;;} .fimg{width: 60px; height: 60px; background: #eee; border-radius: 5px; overflow: hidden;} .fimg img{width: 60px; height: 60px;} .ftitle{color: #555; font-size: 16px; font-weight: bolder;} .fsmall{margin: 5px 0; font-size: 12px; color: #ccc;} .fprice{color: orangered; font-size: 16px; font-weight: bolder;} .fprice .old{font-size: 12px; color: #ccc; font-weight: normal;} .fprice .add{padding: 0 5px; padding-bottom: 2px; border-radius: 30px; background: orange; color: #555; text-decoration: none; float: right;}</style>';
    h += '<table>';
    h += '<tr>';
    //左侧分类
    h += '<td id="cateList">';
    //for (i = 0; i < cates.length; i ++) {
    //    h += '<div class="liCate">';
    //    h += cates[i].title;
    //    h += '</div>';
    //}
    h += '</td>';
    //右侧菜谱
    h += '<td style="padding: 10px 0;" id="goodsList">';
    //for (i = 0; i < foods.length; i ++) {
    //    h += '<table style="margin-bottom: 10px;"><tr>';
    //    h += '<td width="60">';
    //    h += '<div class="fimg">';
    //    h += '<img src="' + foods[i].cover + '"/>';
    //    h += '</div>';
    //    h += '</td>';
    //    h += '<td width="' + (cw - 60) + '">';
    //    h += '<div class="ftitle">' + foods[i].title + '</div>';
    //    h += '<div class="fsmall">月售' + foods[i].monthSale + ' &nbsp; 点赞' + foods[i].likeNum + '</div>';
    //    h += '<div class="fprice">';
    //    h += '￥' + foods[i].price;
    //    h += '<span class="old"> ￥' + (foods[i].price * 1.2) + '</span>';
    //    h += '<a href="javascript:;" class="add">+</a>';
    //    h += '</div>';
    //    h += '</td>';
    //    h += '</tr></table>';
    //}
    h += '</td>';
    h += '</tr>';
    h += '</table>';
    $('#body1').html(h);
    //评价
    h = '<style type="text/css">#pl-body { margin: 10px 5%; } .pl-l { width: 40px; text-align: center; } .pl-l img { width: 30px; height: 30px; border-radius: 20px; background: #eee; box-shadow:1px 1px 5px #ccc; } .pl-l div { width: 40px; font-size: 12px; color: #ccc; } .pl-r  { padding: 5px 10px; font-size: 12px; } .pl-r div { color: #888; } #addbtn { padding: 5px 5%; width: 90%; background: #fff; border: 0; border-top: 1px solid #ccc; position: fixed; bottom: 0; z-index: 10; } #addbtn input { padding: 10px; width: 65%; background: #efefef; border: 0; border-radius: 10px; font-size: 12px; } #addbtn a { padding: 8px 10px; background: #0088cc; border: 0; border-radius: 5px; font-size: 12px; color: #fff; float: right; } .div-hr { height: 50px; }</style>';
    h += '<table id="pl-body">';
    //h += '<tr>';
    //h += '<td class="pl-l">';
    //h += '<img src="../../../imgs/mpPlay.png"/>';
    //h += '<div>用户名</div>';
    //h += '</td>';
    //h += '<td class="pl-r">';
    //h += '<div style="color: #ccc;">2024-02-02</div>';
    //h += '<div style="width: ' + (cw * 1 - 80) + 'px; max-height: 50px; word-wrap: break-word; overflow: hidden;">11111111111111111111111111111111122222222222222222222222</div>';
    //h += '</td>';
    //h += '</tr>';
    h += '<tr><td colspan="2" style="width: ' + cw + 'px; text-align: center; font-size: 12px; color: #888;">没有评论</td></tr>';
    h += '</table>';
    h += '<div style="margin-bottom: 10px; padding: 10px 0; text-align: center; font-size: 12px; color: #888;" onclick="getCommentList();">点击更多</div>';
    h += '<div class="div-hr"></div>';
    h += '<div id="addbtn"><input type="text" id="pl-txt" placeholder="有爱评论，说点儿好听的" value=""/><a href="javascript:;" onclick="addComment();">发布评论</a></div>';
    $('#body2').html(h);
    //关注
    h = '<style type="text/css">#gz-list table { margin: 0 5%; margin-bottom: 10px; width: 90%; border-collapse: collapse; } #gz-list td { padding: 10px; font-size: 12px; border: 1px solid #efefef; } #gz-list .gz-l { width: 30%; text-align: right; color: #888; } #gz-list .gz-r { width: 60%; text-align: center; color: #555; } #gz-list .gzhr { border-bottom: 1px solid #80d4ff; }</style>';
    h += '<div id="gz-list">';
    h += '<table>';
    h += '<tr><td colspan="2" style="width: ' + cw + 'px; text-align: center; font-size: 12px; color: #888;">没有关注</td></tr>';
    //h += '<tr>';
    //h += '<td class="gz-l">用户</td>';
    //h += '<td class="gz-r">用户名</td>';
    //h += '</tr>';
    //h += '<tr>';
    //h += '<td class="gz-l gzhr">更新时间</td>';
    //h += '<td class="gz-r gzhr">时间时间</td>';
    //h += '</tr>';
    h += '</table>';
    h += '</div>';
    h += '<div style="margin-bottom: 10px; padding: 10px 0; text-align: center; font-size: 12px; color: #888;" onclick="getFollowList();">点击更多</div>';
    h += '<div class="div-hr"></div>';
    $('#body3').html(h);
}


//获取分类
function getCateList(){
    //if (token == '') {
    //    msgPop({msg: '没有登录'});
    //    setTimeout(function(){
    //        window.location.href = '/login.html?code=' + code;
    //    }, 1000);
    //    return
    //}
    var formData = {
        token: token
    };
    $.ajax({
        type: apis.shop1CateList.method,
        url: apis.shop1CateList.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            cateList = res.data;
            getCateHtml();
            getGoodsList(0);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//左侧分类字符串
function getCateHtml(){
    var h = '', i, cates = cateList;
    //左侧分类
    h += '<td>';
    h += '<div class="liCate" id="li-0" onclick="getGoodsList(0);">';
    h += '所有';
    h += '</div>';
    for (i = 0; i < cates.length; i ++) {
        h += '<div class="liCate" id="li-' + cates[i].id + '" onclick="getGoodsList(' + cates[i].id + ');">';
        h += cates[i].title;
        h += '</div>';
    }
    h += '</td>';
    $('#cateList').html(h);
}


//获取商品content
function getGoodsList(v){
    //if (token == '') {
    //    msgPop({msg: '没有登录'});
    //    setTimeout(function(){
    //        window.location.href = '/login.html?code=' + code;
    //    }, 1000);
    //    return
    //}
    var formData = {
        token: token,
        code: code,
        cateId: v
    };
    $.ajax({
        type: apis.shop1GoodsList.method,
        url: apis.shop1GoodsList.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            goodsList = res.data;
            getGoodsHtml();
            $('.liCate').removeClass('liClick');
            $('#li-' + v).addClass('liClick');
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//右侧商品字符串
function getGoodsHtml(){
    var h = '', i, foods = goodsList;
    var gid, title, img, monthSale, likeNum, price;
    for (i = 0; i < foods.length; i ++) {
        gid = foods[i].id;
        title = foods[i].gname;
        img = foods[i].img;
        monthSale = foods[i].month_sale;
        likeNum = foods[i].follow;
        price = foods[i].price;
        h += '<table style="margin-bottom: 10px;"><tr>';
        h += '<td width="60">';
        h += '<div class="fimg" onclick="goodsShow(' + gid + ');">';
        if (img != '') {
            h += '<img src="' + img + '"/>';
        }
        h += '</div>';
        h += '</td>';
        h += '<td width="' + (cw - 60) + '">';
        h += '<div class="ftitle" onclick="goodsShow(' + gid + ');">' + title + '</div>';
        h += '<div class="fsmall">月售' + monthSale + ' &nbsp; 点赞' + likeNum+ '</div>';
        h += '<div class="fprice">';
        h += '￥' + price;
        h += '<span class="old"> ￥' + (price * 1.2).toFixed(2) + '</span>';
        h += '<a href="javascript:;" class="add" onclick="addCart(' + gid + ');">+</a>';
        h += '<input type="hidden" id="gcode-' + gid + '" value="' + foods[i].gcode + '"/>';
        h += '</div>';
        h += '</td>';
        h += '</tr></table>';
    }
    $('#goodsList').html(h);
}


//获取评论
function getCommentList(){
    if (commentList.pages.moreFlag == 1) {
        msgPop({msg: '没有了'});
        return
    }
    //if (token == '') {
    //    msgPop({msg: '没有登录'});
    //    setTimeout(function(){
    //        window.location.href = '/login.html?code=' + code;
    //    }, 1000);
    //    return
    //}
    var formData = {
        token: token,
        pageStart: commentList.pages.start,
        pageLimit: commentList.pages.limit
    };
    console.log(formData);
    $.ajax({
        type: apis.shop1CommentList.method,
        url: apis.shop1CommentList.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            for (var i = 0; i < res.data.length; i ++) {
                commentList.data.push(res.data[i]);
                commentList.total ++;
            }
            if (res.data.length == commentList.pages.limit) {
                commentList.pages.start ++;
                commentList.pages.moreFlag = 0;
            } else {
                commentList.pages.moreFlag = 1;
            }
            getCommentHtml();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//评论HTML
function getCommentHtml(){
    var d = commentList.data, total = commentList.total;
    var userInfo = getUserInfo();
    $('#m-1-total').html(total);
    var h = '', id, addDates, sender, accept;
    for (var i = 0; i < d.length; i ++) {
        id = d[i].id;
        sender = d[i].uid;
        addDates = d[i].addtime.split(' ');
        h += '<tr>';
        h += '<td class="pl-l">';
        h += '<img src="../../../imgs/mpPlay.png"/>';
        h += '<div>' + strSuffix(sender, 5) + '</div>';
        h += '</td>';
        h += '<td class="pl-r" onclick="aiteComment(' + id + ');">';
        h += '<div>';
        h += '对<b id="accept-' + id + '">';
        h += userInfo.uid == sender ? '版主' : strSuffix(sender, 6);
        h += '</b>：';
        h += '<span style="color: #ccc; float: right;">' + addDates[0] + '</span>';
        h += '</div>';
        h += '<div style="width: ' + (cw * 1 - 80) + 'px; max-height: 50px; word-wrap: break-word; overflow: hidden;">' + d[i].content + '</div>';
        h += '</td>';
        h += '</tr>';
    }
    $('#pl-body').html(h);
}


//评论艾特新增
function aiteComment(id){
    var accept = $('#accept-' + id).html();
    $('#pl-txt').attr('placeholder', '回复@' + accept);
}


//评论新增
function addComment(){
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    var content = $('#pl-txt').val();
    if (content == '') {
        msgPop({msg: '评论没有填写'});
        return
    }
    var formData = {
        token: token,
        content: content
    };
    $.ajax({
        type: apis.shop1CommentAdd.method,
        url: apis.shop1CommentAdd.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg}); return
            }
            msgPop({msg: '发布成功'});
            var newList = [res.data];
            for (var i = 0; i < commentList.data.length; i ++) {
                newList[i + 1] = commentList.data[i];
            }
            commentList.data = newList;
            commentList.total ++;
            getCommentHtml();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//关注列表
function getFollowList(){
    if (followList.pages.moreFlag == 1) {
        msgPop({msg: '没有了'});
        return
    }
    //if (token == '') {
    //    msgPop({msg: '没有登录'});
    //    setTimeout(function(){
    //        window.location.href = '/login.html?code=' + code;
    //    }, 1000);
    //    return
    //}
    var formData = {
        token: token,
        pageStart: followList.pages.start,
        pageLimit: followList.pages.limit
    };
    $.ajax({
        type: apis.shop1FollowList.method,
        url: apis.shop1FollowList.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            var newList = res.data;
            for (var i = 0; i < followList.data.length; i ++) {
                newList[i + 1] = followList.data[i];
            }
            followList.data = newList;
            followList.total ++;
            if (res.data.length == followList.pages.limit) {
                followList.pages.start ++;
                followList.pages.moreFlag = 0;
            } else {
                followList.pages.moreFlag = 1;
            }
            getFollowHtml();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//关注字符串
function getFollowHtml(){
    var h = '', i;
    var userId, addtimes, gcode;
    for (i = 0; i < followList.data.length; i ++) {
        userId = followList.data[i].uid;
        gcode = followList.data[i].gcode;
        addtimes = followList.data[i].addtime.split(' ');
        h += '<table>';
        h += '<tr>';
        h += '<td class="gz-l">用户</td>';
        h += '<td class="gz-r">' + userId + '</td>';
        h += '</tr>';
        h += '<tr>';
        h += '<td class="gz-l">类型</td>';
        h += '<td class="gz-r">';
        h += gcode=='' ? '门店' : '商品';
        h += '</td>';
        h += '</tr>';
        h += '<tr>';
        h += '<td class="gz-l gzhr">关注时间</td>';
        h += '<td class="gz-r gzhr">' + addtimes[0] + '</td>';
        h += '</tr>';
        h += '</table>';
    }
    $('#gz-list').html(h);
}


//关注设置
function setFollow(){
    if (code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    var formData = {
        token: token,
        code: code,
    };
    $.ajax({
        type: apis.shop1FollowModify.method,
        url: apis.shop1FollowModify.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            if (followList.isfollow == 0) {
                msgPop({msg: '关注成功'});
            } else {
                msgPop({msg: '取关成功'});
            }
            window.location.reload();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//商品详情
function goodsShow(v){
    var h = '', i, goodsOne = '';
    for (i = 0; i < goodsList.length; i ++) {
        if (goodsList[i].id == v) {
            goodsOne = goodsList[i];
        }
    }
    console.log(goodsOne);
    if (goodsOne == '') {
        msgPop({msg: '商品错误'});
        return
    }
    h += '<div style="position: fixed; top: 0; left: 0; z-index: 10000;">';
    h += '<div style="width: ' + (cw) + 'px; height: ' + (ch) + 'px; background: #000; opacity: 0.2; position: fixed; top: 0; left: 0; z-index: 10000;" onclick="$(\'#onePop\').html(\'\');"></div>';
    h += '<div style="padding: 5px 5%; width: ' + (cw * 0.9) + 'px; height: ' + (ch - 40) + 'px; text-align: center; background: #fff; border-top: 1px solid #888; border-top-left-radius: 5px; border-top-right-radius: 5px; box-shadow: 0 0 10px #888; overflow: auto; position: fixed; top: 40px; left: 0; z-index: 10000;">';
    h += '<style type="text/css">#goodsClose {padding: 10px 0; width: 90%; text-align: center; font-size: 12px; color: red; border: 0; border-bottom: 1px solid #eee; background: #fff; position: fixed; top: 42px; z-index: 10000 } #goodsOne { margin-top: 40px; margin-bottom: 50px; width: 100%; } #goodsOne td {padding: 10px;} #goodsOne #img { width: ' + (cw * 0.9 - 20) + 'px; height: ' + (cw * 0.9 - 20) + 'px; background: #eee; } #goodsOne img { width: ' + (cw) + 'px; } #goodsOne .td-l { width: 30%; color: #888; text-align: right; } #goodsOne .td-r { width: 60%; } #goodsOne .edit { margin-left: 10px; padding: 2px 10px; color: #0088cc; border: 1px solid #0088cc; border-radius: 5px; font-size: 12px; }</style>';
    h += '<div id="goodsClose" onclick="$(\'#onePop\').html(\'\');">关 闭</div>';
    h += '<table id="goodsOne">';
    h += '<tr>';
    h += '<td colspan="2">';
    h += '<div id="img">';
    if (goodsOne.img != '') {
        h += '<img src="' + goodsOne.img + '"/>';
    } else {
        h += '<div style="padding-top: 40%; text-align: center; color: #ccc; font-size: 12px;">暂无图片</div>';
    }
    h += '</div>';
    h += '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="td-l">商品名</td>';
    h += '<td class="td-r">' + goodsOne.gname + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="td-l">单价</td>';
    h += '<td class="td-r">' + goodsOne.price + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="td-l">分类</td>';
    h += '<td class="td-r">' + goodsOne.cate_id + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="td-l">商品描述</td>';
    h += '<td class="td-r">' + goodsOne.describe + '</td>';
    h += '</tr>';
    h += '<tr>';
    h += '<td class="td-l">关注量</td>';
    h += '<td class="td-r">';
    h += '<span id="gzl">' + goodsOne.follow + '</span>';
    h += '<span id="gfbtn"></span>';
    h += '<input type="hidden" id="gcode' + goodsOne.id + '" value="' + goodsOne.gcode + '"/>';
    h += '</td>';
    h += '</tr>';
    h += '</table>';
    h += '</div>';
    $('#onePop').html(h);
    existGoodsFollow(goodsOne.id);
}


//获取商品关注
function existGoodsFollow(v){
    var gcode = $('#gcode' + v).val();
    if (formList.shop_code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    //if (token == '') {
    //    msgPop({msg: '没有登录'});
    //    setTimeout(function(){
    //        window.location.href = '/login.html?code=' + code;
    //    }, 1000);
    //    return
    //}
    var formData = {
        token: token,
        gcode: gcode
    };
    $.ajax({
        type: apis.shop1ExistGoodsFollow.method,
        url: apis.shop1ExistGoodsFollow.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code == 0) {
                //msgPop({msg: res.msg});
                return
            }
            var h = '';
            h += '<span class="edit" onclick="setGoodsFollow(' + v + ');">未关注</span>';
            //h += '<input type="hidden" id="gcode' + v + '" value="' + gcode + '"/>';
            $('#gfbtn').html(h);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//关注商品设置
function setGoodsFollow(v){
    var gcode = $('#gcode' + v).val();
    if (formList.shop_code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    var formData = {
        token: token,
        shopCode: formList.shop_code,
        gcode: gcode
    };
    $.ajax({
        type: apis.shop1GoodsFollowAdd.method,
        url: apis.shop1GoodsFollowAdd.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg});
                return
            }
            msgPop({msg: '关注成功'});
            var gzl = $('#gzl');
            gzl.html(gzl.html() * 1 + 1);
            $('#gfbtn').html('');
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//购物车影子
function cartBottom(){
    var h = '';
    h += '<style type="text/css">#cartBtm { margin: 0 ' + (cw * 0.2) + 'px; width: ' + (cw * 0.6) + 'px; height: 45px; background: #333; text-align: center; border-radius: 10px; position: fixed; bottom: -10px; z-index: 10000; } #cartBtm .menu { padding: 5px 0; width: 50%; font-size: 12px; color: #fff; float: left; }</style>';
    h += '<div id="cartBtm">';
    h += '<div class="menu" onclick="getCartList();">购物车</div>';
    h += '<div class="menu" onclick="getOrderOne();">我的订单</div>';
    h += '</div>';
    $('#cartPop').html(h);
}


//购物车添加
function addCart(v){
    var gcode = $('#gcode-' + v).val();
    if (formList.shop_code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    var formData = {
        token: token,
        shopCode: formList.shop_code,
        gcode: gcode
    };
    //console.log(formData); return
    $.ajax({
        type: apis.shop1CartAdd.method,
        url: apis.shop1CartAdd.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg});
                return
            }
            msgPop({msg: '添加成功'});
            getCartList();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//购物车弹窗
function getCartList(){
    if (formList.shop_code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    var formData = {
        token: token,
        shopCode: formList.shop_code
    };
    console.log(formData);
    $.ajax({
        type: apis.shop1CartList.method,
        url: apis.shop1CartList.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                cartList = [];
                getCartHtml();
                return
            }
            cartList = res.data;
            getCartHtml();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//购物车字符串
function getCartHtml(){
    var h = '', i;
    h += '<div style="position: fixed; top: 0; left: 0; z-index: 1000;">';
    h += '<div style="width: ' + (cw) + 'px; height: ' + (ch) + 'px; background: #000; opacity: 0.2; position: fixed; top: 0; left: 0; z-index: 1000;" onclick="cartBottom();"></div>';
    h += '<div style="padding: 5px 5%; width: ' + (cw * 0.9) + 'px; height: ' + (ch - 40) + 'px; text-align: center; background: #fff; border-top: 1px solid #888; border-top-left-radius: 5px; border-top-right-radius: 5px; box-shadow: 0 0 10px #888; overflow: auto; position: fixed; top: 40px; left: 0; z-index: 1000;">';
    h += '<style type="text/css">#cartClose {padding: 10px 0; width: 90%; text-align: left; font-weight: bolder; border: 0; border-bottom: 1px solid #eee; background: #fff; position: fixed; top: 42px; z-index: 1000; } #cartClose span {font-size: 12px; color: red; float: right; } #cart-list { margin-top: 50px; width: 100%; color: #888; } #cart-list .tdhr { margin: 10px 0; height: 1px; background: #eee; } #cart-list .img { width: 80px; height: 80px; border-radius: 5px; border: 1px solid #eee; box-shadow: 0 0 5px #888; overflow: hidden; } #cart-list img { width: 80px; height: 80px; } #cart-list .tdm { ;width: 100px; text-align: left; } #cart-list .tdr { text-align: right; } #cart-list .tdr a { margin-left: 5px; padding: 0 8px; text-decoration: none; background: #0088cc; color: #fff; border-radius: 2px; } #toOrder { margin-left: 10px; padding: 4px 10px; text-decoration: none; color: #fff; background: #0088cc; font-size: 12px; border-radius: 5px; }</style>';
    h += '<div id="cartClose" onclick="cartBottom();">';
    h += '购物车';
    h += '<a href="javascript:;" id="toOrder" onclick="addOrder();">下单</a>';
    h += '<span>关 闭</span>';
    h += '</div>';
    h += '<table id="cart-list">';
    //统计
    h += '<tr>';
    h += '<td colspan="5">';
    h += '商品数：<b id="cartGoodsNum">1</b>，';
    h += '总金额：<b id="cartGoodsPrice">￥1</b>';
    h += '</td>';
    h += '</tr>';
    h += '<tr><td colspan="5"><div class="tdhr"></div></td></tr>';
    /////////////////////////////////////
    //h += '<tr>';
    //h += '<td>没有商品</td>';
    //h += '</tr>';
    /////////////////////////////////////
    //h += '<tr>';
    //h += '<td rowspan="3" width="100">';
    //h += '<div class="img">';
    //h += '<img src="../../../imgs/bai.png">';
    //h += '</div>';
    //h += '<td class="tdm">商品名</td>';
    //h += '<td class="tdr"></td>';
    //h += '</tr>';
    //h += '<tr>';
    //h += '<td class="tdm">月售0 点赞0</td>';
    //h += '<td class="tdr">';
    //h += '<a href="javascript:;">-</a>';
    //h += '<a href="javascript:;">+</a>';
    //h += '</td>';
    //h += '</tr>';
    //h += '<tr>';
    //h += '<td class="tdm">单价';
    //h += '<b style="color: red; font-size: 20px;">￥0</b>';
    //h += '</td>';
    //h += '<td class="tdr" style="text-align: center;">';
    //h += '<span style="font-size: 12px;">数量：</span>';
    //h += '<span id="cartNum">0</span>';
    //h += '</td>';
    //h += '</tr>';
    //h += '<tr><td colspan="5"><div class="tdhr"></div></td></tr>';
    /////////////////////////////////////
    console.log(cartList);
    var cartGoodsNum = 0, cartGoodsPrice = 0;
    if (cartList.length == 0) {
        h += '<tr>';
        h += '<td>没有商品</td>';
        h += '</tr>';
    } else {
        for (i = 0; i < cartList.length; i ++) {
            h += '<tr>';
            h += '<td rowspan="3" width="100">';
            h += '<div class="img">';
            if (cartList[i].gimg != '') {
                h += '<img src="' + cartList[i].gimg + '">';
            }
            h += '</div>';
            h += '<td class="tdm">' + cartList[i].title + '</td>';
            h += '<td class="tdr"></td>';
            h += '</tr>';
            h += '<tr>';
            h += '<td class="tdm">月售' + cartList[i].monthSale + ' 点赞' + cartList[i].follow + '</td>';
            h += '<td class="tdr">';
            h += '<a href="javascript:;" onclick="delCart(' + cartList[i].gid + ');">-</a>';
            h += '<a href="javascript:;" onclick="addCart(' + cartList[i].gid + ');">+</a>';
            h += '<input type="hidden" id="cartno' + cartList[i].gid + '" value="' + cartList[i].cartno + '"/>';
            h += '</td>';
            h += '</tr>';
            h += '<tr>';
            h += '<td class="tdm">单价';
            h += '<b style="color: red; font-size: 20px;">￥' + cartList[i].price + '</b>';
            h += '</td>';
            h += '<td class="tdr" style="text-align: center;">';
            h += '<span style="font-size: 12px;">数量：</span>';
            h += '<span id="cartNum">' + cartList[i].num + '</span>';
            h += '</td>';
            h += '</tr>';
            h += '<tr><td colspan="5"><div class="tdhr"></div></td></tr>';
            cartGoodsNum += cartList[i].num;
            cartGoodsPrice += cartList[i].num * cartList[i].price;
        }
    }
    h += '</table>';
    h += '</div>';
    h += '</div>';
    $('#cartPop').html(h);
    $('#cartGoodsNum').html(cartGoodsNum);
    $('#cartGoodsPrice').html('￥' + cartGoodsPrice + '元');
}


//购物车减少
function delCart(v){
    var cartno = $('#cartno' + v).val();
    if (formList.shop_code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    var formData = {
        token: token,
        cartno: cartno
    };
    console.log(formData);
    $.ajax({
        type: apis.shop1CartDel.method,
        url: apis.shop1CartDel.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg});
                return
            }
            msgPop({msg: '移除成功'});
            getCartList();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//订单新增
function addOrder(){
    if (formList.shop_code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    var formData = {
        token: token,
        shopCode: formList.shop_code
    };
    console.log(formData);
    $.ajax({
        type: apis.shop1OrderAdd.method,
        url: apis.shop1OrderAdd.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg});
                return
            }
            getOrderOne();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//订单删除
function delOrder(v){
    var orderno = $('#orderno' + v).val();
    if (formList.shop_code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    if (orderno == '') {
        msgPop({msg: '订单错误'});
        return
    }
    var formData = {
        token: token,
        shopCode: formList.shop_code,
        orderno: orderno
    };
    console.log(formData);
    $.ajax({
        type: apis.shop1OrderDel.method,
        url: apis.shop1OrderDel.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg});
                return
            }
            msgPop({msg: '删除成功'});
            orderList = {
                orderno: '',
                gnum: 0,
                totalPrice: 0,
                goodsList: [] //商品列表
            };
            getOrderHtml();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//订单获取
function getOrderOne(){
    if (formList.shop_code == '') {
        msgPop({msg: '门店错误'});
        return
    }
    if (token == '') {
        msgPop({msg: '没有登录'});
        setTimeout(function(){
            window.location.href = '/login.html?code=' + code;
        }, 1000);
        return
    }
    var formData = {
        token: token,
        shopCode: formList.shop_code
    };
    console.log(formData);
    $.ajax({
        type: apis.shop1OrderOne.method,
        url: apis.shop1OrderOne.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                getOrderHtml();
                return
            }
            orderList = res.data;
            console.log(orderList);
            getOrderHtml();
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//订单字符串
function getOrderHtml(){
    var h = '', i;
    h += '<div style="position: fixed; top: 0; left: 0; z-index: 1000;">';
    h += '<div style="width: ' + (cw) + 'px; height: ' + (ch) + 'px; background: #000; opacity: 0.2; position: fixed; top: 0; left: 0; z-index: 1000;" onclick="cartBottom();"></div>';
    h += '<div style="padding: 5px 5%; width: ' + (cw * 0.9) + 'px; height: ' + (ch - 40) + 'px; text-align: center; background: #fff; border-top: 1px solid #888; border-top-left-radius: 5px; border-top-right-radius: 5px; box-shadow: 0 0 10px #888; overflow: auto; position: fixed; top: 40px; left: 0; z-index: 1000;">';
    h += '<style type="text/css">#cartClose {padding: 10px 0; width: 90%; text-align: left; font-weight: bolder; border: 0; border-bottom: 1px solid #eee; background: #fff; position: fixed; top: 42px; z-index: 1000; } #cartClose span {font-size: 12px; color: red; float: right; } #cart-list { margin-top: 50px; width: 100%; color: #888; } #cart-list .tdhr { margin: 10px 0; height: 1px; background: #eee; } #cart-list .img { width: 80px; height: 80px; border-radius: 5px; border: 1px solid #eee; box-shadow: 0 0 5px #888; overflow: hidden; } #cart-list img { width: 80px; height: 80px; } #cart-list .tdm { ;width: 100px; text-align: left; } #cart-list .tdr { text-align: right; } #cart-list .tdr a { margin-left: 5px; padding: 0 8px; text-decoration: none; background: #0088cc; color: #fff; border-radius: 2px; } #toOrder { margin-left: 10px; padding: 4px 10px; text-decoration: none; color: #fff; background: red; font-size: 12px; border-radius: 5px; }</style>';
    h += '<div id="cartClose" onclick="cartBottom();">';
    h += '我的订单';
    h += '<a href="javascript:;" id="toOrder" onclick="delOrder(' + orderList.id + ');">删除</a>';
    h += '<input type="hidden" id="orderno' + orderList.id + '" value="' + orderList.orderno + '"/>';
    h += '<span>关 闭</span>';
    h += '</div>';
    h += '<table id="cart-list">';
    //统计
    h += '<tr>';
    h += '<td colspan="5">';
    h += '商品数：<b>' + orderList.gnum + '</b>，';
    h += '总金额：<b>￥' + orderList.totalPrice + '</b>';
    h += '</td>';
    h += '</tr>';
    h += '<tr><td colspan="5"><div class="tdhr"></div></td></tr>';
    /////////////////////////////////////
    //h += '<tr>';
    //h += '<td>没有商品</td>';
    //h += '</tr>';
    /////////////////////////////////////
    //h += '<tr>';
    //h += '<td rowspan="3" width="100">';
    //h += '<div class="img">';
    //h += '<img src="../../../imgs/bai.png">';
    //h += '</div>';
    //h += '<td class="tdm">商品名</td>';
    //h += '<td class="tdr"></td>';
    //h += '</tr>';
    //h += '<tr>';
    //h += '<td class="tdm">月售0 点赞0</td>';
    //h += '<td class="tdr"></td>';
    //h += '</tr>';
    //h += '<tr>';
    //h += '<td class="tdm">单价';
    //h += '<b style="color: red; font-size: 20px;">￥0</b>';
    //h += '</td>';
    //h += '<td class="tdr" style="text-align: center;">';
    //h += '<span style="font-size: 12px;">数量：</span>';
    //h += '<span id="cartNum">0</span>';
    //h += '</td>';
    //h += '</tr>';
    //h += '<tr><td colspan="5"><div class="tdhr"></div></td></tr>';
    /////////////////////////////////////
    console.log(orderList);
    if (orderList.goodsList.length == 0) {
        h += '<tr>';
        h += '<td>没有商品</td>';
        h += '</tr>';
        h += '</table>';
        h += '</div>';
        h += '</div>';
        $('#cartPop').html(h);
        return
    }
    var gs = orderList.goodsList;
    for (i = 0; i < gs.length; i ++) {
        h += '<tr>';
        h += '<td rowspan="3" width="100">';
        h += '<div class="img">';
        if (gs[i].img != '') {
            h += '<img src="' + gs[i].img + '">';
        }
        h += '</div>';
        h += '<td class="tdm">' + gs[i].title + '</td>';
        h += '<td class="tdr"></td>';
        h += '</tr>';
        h += '<tr>';
        h += '<td class="tdm">数量：' + gs[i].num + '</td>';
        h += '<td class="tdr"></td>';
        h += '</tr>';
        h += '<tr>';
        h += '<td class="tdm">单价';
        h += '<b style="color: red; font-size: 20px;">￥' + gs[i].price + '</b>';
        h += '</td>';
        h += '</tr>';
        h += '<tr><td colspan="5"><div class="tdhr"></div></td></tr>';
    }
    h += '</table>';
    h += '</div>';
    h += '</div>';
    $('#cartPop').html(h);
}